//
//  Team9InspirationController.m
//  Team9Project
//
//  Created by 朱嘉祺 on 15/10/12.
//  Copyright © 2015年 apple. All rights reserved.
//

#import "Team9InspirationController.h"
#import "Team9InspirationCollectionViewCell.h"
#import "JQAFNetworkTool.h"
#import "Team9InspirationModel.h"
#import <UIImageView+WebCache.h>
#import <Masonry.h>
#import "Team9ClassifyTableViewCell.h"
#import "Team9TagsModel.h"
#import "Team9AlbumModel.h"
#import "Team9AlbumTableViewCell.h"
#import "Team9PhotoViewController.h"
#import "Team9DesignVC.h"
#import <MJRefresh.h>
#import "Team9BaseView.h"
#import "Team9BaseTableViewCell2.h"

#define WID 375.0

@interface Team9InspirationController ()<UICollectionViewDataSource,UICollectionViewDelegate,UITableViewDataSource,UITableViewDelegate,UIScrollViewDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) NSMutableArray *photoArr;
@property (nonatomic, strong) UIButton *photoButton;
@property (nonatomic, strong) Team9BaseView *buttonView;
@property (nonatomic, strong) Team9BaseView *line;
@property (nonatomic, strong) UIButton *hotButton;
@property (nonatomic, assign) BOOL isSelect;
@property (nonatomic, strong) UIView *mainView;
@property (nonatomic, strong) NSMutableArray *tagsArr;
@property (nonatomic, strong) NSMutableArray *styleArr;
@property (nonatomic, strong) UITableView *classifyTableView;
@property (nonatomic, strong) UITableView *hotTableView;
@property (nonatomic, strong) NSMutableArray *hotArr;
@property (nonatomic, strong) NSMutableArray *classifyArr;
@property (nonatomic, strong) UIScrollView *baseScrollView;
@property (nonatomic, strong) UIButton *albumButton;
@property (nonatomic, strong) UITableView *albumTableView;
@property (nonatomic, strong) NSMutableArray *albumArr;
@property (nonatomic, strong) Team9TagsModel *tagsModel;
@property (nonatomic, assign) NSInteger count;
@property (nonatomic, strong) Team9BaseView *lineView;
@property (nonatomic, copy) NSString *albumStr;
@property (nonatomic, copy) NSString *hotString;
@property (nonatomic, strong) Team9EmptyTool *empty2;
@property (nonatomic, strong) Team9EmptyTool *empty3;
@property (nonatomic, strong) Team9RefreshTool *tool2;
@property (nonatomic, assign) NSInteger selectRow;
@property (nonatomic, assign) BOOL select;

@end

@implementation Team9InspirationController


- (void)changePage:(NSNotification *)info{
    NSDictionary *dic = info.userInfo;
    self.url = dic[@"url"];
    self.hotString = dic[@"type"];
    [self.hotButton setTitle:dic[@"type"] forState:UIControlStateNormal];
       if (_albumTableView && _collectionView) {
        [self createData];
    }
}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    if (self.baseScrollView.contentOffset.x == 0) {
        self.baseScrollView.contentOffset = CGPointMake(0, 0);
        if ([Team9EveningType shareEvening].eveningFailling) {
            [self.photoButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
            [self.albumButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        } else {
            [self.photoButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
            [self.albumButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        }
    }else{
        self.baseScrollView.contentOffset = CGPointMake(WIDTH, 0);
        if ([Team9EveningType shareEvening].eveningFailling) {
            [self.photoButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [self.albumButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        } else {
            [self.photoButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [self.albumButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        }
    }
    [self createData];
}

- (void)changecolor{
    [super changecolor];
    if ([Team9EveningType shareEvening].eveningFailling) {
        self.lineView.backgroundColor = [UIColor greenColor];
        self.albumTableView.backgroundColor = [UIColor blackColor];
        self.collectionView.backgroundColor = [UIColor blackColor];
        self.classifyTableView.backgroundColor = [UIColor blackColor];
        self.hotTableView.backgroundColor = [UIColor colorWithWhite:0.15 alpha:1];
        [self.hotButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        if (self.select) {
            [self.photoButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [self.albumButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        } else {
            [self.photoButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
            [self.albumButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        }
    } else{
        [self.hotButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        self.lineView.backgroundColor = [UIColor orangeColor];
        self.collectionView.backgroundColor = [UIColor whiteColor];
        self.albumTableView.backgroundColor = [UIColor whiteColor];
        self.classifyTableView.backgroundColor = [UIColor whiteColor];
        self.hotTableView.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1];
        if (self.select){
            [self.photoButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [self.albumButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        } else {
            [self.photoButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
            [self.albumButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        }
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.navigationController.navigationBar.translucent = NO;
    
    self.baseScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEGHT)];
    self.baseScrollView.contentSize = CGSizeMake(WIDTH * 2, HEGHT - 64 - 49);
    self.baseScrollView.pagingEnabled = YES;
    self.baseScrollView.delegate = self;
    [self.view addSubview:self.baseScrollView];
    self.baseScrollView.bounces = NO;
    self.baseScrollView.showsHorizontalScrollIndicator = NO;
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake(170 / WID * WIDTH, 170 / WID * WIDTH);
    flowLayout.minimumInteritemSpacing = 10 / WID * WIDTH;
    flowLayout.minimumLineSpacing = 10 / WID * WIDTH;

#pragma mark 图片的CollectionView
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    [self.baseScrollView addSubview:self.collectionView];
    [self.collectionView registerClass:[Team9InspirationCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
    self.collectionView.frame = CGRectMake(0, 40 / WID * WIDTH, WIDTH, HEGHT - 64 - 49);
    self.collectionView.contentInset = UIEdgeInsetsMake(5 / WID * WIDTH, 10 / WID * WIDTH, 10 / WID * WIDTH , 10 / WID * WIDTH);
    self.collectionView.showsVerticalScrollIndicator = NO;

#pragma mark 画册的tableView
    self.albumTableView = [[UITableView alloc] initWithFrame:CGRectMake(WIDTH, 40 / WID * WIDTH, WIDTH, HEGHT - 64 - 49) style:UITableViewStylePlain];
    self.albumTableView.delegate = self;
    self.albumTableView.dataSource = self;
    [self.baseScrollView addSubview:self.albumTableView];
    self.albumTableView.rowHeight = 130 / WID * WIDTH;
    self.albumTableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
    self.albumTableView.showsVerticalScrollIndicator = NO;
    UIView *aView = [[UIView alloc] init];
    self.albumTableView.tableFooterView = aView;
    
#pragma mark 热门页面加tableView的view
    self.mainView = [[UIView alloc] init];
    self.mainView.frame = CGRectMake(0, 0, WIDTH, HEGHT);
    self.mainView.backgroundColor = [UIColor blackColor];
    [self.view addSubview:self.mainView];
    
    
#pragma mark 热门tableView
    self.hotTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 120 / WID * WIDTH, HEGHT - 64) style:UITableViewStylePlain];
    self.hotTableView.dataSource = self;
    self.hotTableView.delegate = self;
    self.hotTableView.rowHeight = 40 / WID * WIDTH;
    [self.mainView addSubview:self.hotTableView];
    self.hotTableView.scrollEnabled = NO;
    self.hotTableView.separatorStyle = NO;
    
    self.empty3 = [Team9EmptyTool toolWithScrollView:self.classifyTableView];
#pragma mark 分类的tableView
    self.classifyTableView = [[UITableView alloc] initWithFrame:CGRectMake(120 / WID * WIDTH, 0, 255 / WID * WIDTH, HEGHT - 64 - 49) style:UITableViewStylePlain];
    self.classifyTableView.dataSource = self;
    self.classifyTableView.delegate = self;
    self.classifyTableView.rowHeight = 40 / WID * WIDTH;
    [self.mainView addSubview:self.classifyTableView];
    self.classifyTableView.showsVerticalScrollIndicator = NO;
    
    [self createHeaderView];
    self.isSelect = YES;
    [self.mainView setHidden:YES];
   

#pragma mark 热门button
    self.hotButton = [UIButton buttonWithType:UIButtonTypeSystem];
    self.navigationItem.titleView = _hotButton;
    if (self.hotString) {
        [self.hotButton setTitle:_hotString forState:UIControlStateNormal];
    } else [self.hotButton setTitle:@"热门" forState:UIControlStateNormal];
    
    [self.hotButton addTarget:self action:@selector(hotButton:) forControlEvents:UIControlEventTouchUpInside];
    self.hotButton.tintColor = [UIColor orangeColor];
    
    self.hotButton.frame = CGRectMake(150 / WID * WIDTH, 5 / WID * WIDTH, 75 / WID * WIDTH, 30 / WID * WIDTH);

    self.empty = [Team9EmptyTool toolWithScrollView:self.collectionView];
    self.empty2 = [Team9EmptyTool toolWithScrollView:self.albumTableView];
    self.selectRow = 1;
    [self.hotTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionNone];
    
    [self createData];
    
}

#pragma mark 创建view添加图片,画册按钮
- (void)createHeaderView{
    CGRect screen = [UIScreen mainScreen].bounds;
    screen.size.height = 30 / WID * WIDTH;
    
    self.buttonView = [[Team9BaseView alloc] init];
    self.buttonView.frame = screen;
    [self.view addSubview:self.buttonView];
    self.line = [[Team9BaseView alloc] initWithFrame:CGRectMake(0, screen.size.height, WIDTH, 5 / WID * WIDTH)];
    [self.view addSubview:self.line];
    
    self.photoButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.photoButton setTitle:@"图片" forState:UIControlStateNormal];
    [self.buttonView addSubview:self.photoButton];
    [self.photoButton addTarget:self action:@selector(photoButton:) forControlEvents:UIControlEventTouchUpInside];
    self.photoButton.titleLabel.font = [UIFont systemFontOfSize:15 / WID * WIDTH];
    
    self.albumButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.albumButton setTitle:@"画册" forState:UIControlStateNormal];
    [self.buttonView addSubview:self.albumButton];
    self.albumButton.titleLabel.font = [UIFont systemFontOfSize:15 / WID * WIDTH];
    [self.albumButton addTarget:self action:@selector(albumButton:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.photoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.buttonView);
        make.right.equalTo(self.buttonView.mas_centerX).offset(-5 / WID * WIDTH);
    }];
    [self.albumButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.buttonView);
        make.left.equalTo(self.buttonView.mas_centerX).offset(5 / WID * WIDTH);
    }];
    
    self.lineView = [[Team9BaseView alloc] init];
    [self.view addSubview:self.lineView];
    [self photoButton:self.photoButton];
}

#pragma mark 约束图片按钮
- (void)photoButton:(UIButton *)button{    
    [self.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.photoButton);
        make.height.equalTo(@1);
        [self.lineView.superview updateConstraintsIfNeeded];
    }];
    [self buttonIsPhoto];
    [self.baseScrollView setContentOffset:CGPointMake(0, 0) animated:YES];
}

#pragma mark 约束画册按钮
- (void)albumButton:(UIButton *)button{
    
    [self.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.albumButton);
        make.height.equalTo(@1);
        [self.lineView.superview updateConstraintsIfNeeded];
    }];
    [self buttonIsAlbum];
    [self.baseScrollView setContentOffset:CGPointMake(WIDTH, 0) animated:YES];
}

#pragma mark 按钮与线同步滑动
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (scrollView == self.baseScrollView) {
        CGRect frame = self.lineView.frame;
        CGFloat left = self.photoButton.frame.origin.x;
        CGFloat right = self.albumButton.frame.origin.x;
        CGFloat leftWidth = self.photoButton.frame.size.width;
        CGFloat rightWidth = self.albumButton.frame.size.width;
        CGFloat proportion = scrollView.contentOffset.x / WIDTH;
        frame.origin.x = left + (right - left) * proportion;
        frame.size.width = leftWidth + (rightWidth - leftWidth) * proportion;
        self.lineView.frame = frame;
    }
}

#pragma mark 按钮与线连动
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    if (scrollView == _baseScrollView) {
        if (self.baseScrollView.contentOffset.x == 0) {
            [self.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.right.bottom.equalTo(self.photoButton);
                make.height.equalTo(@1);
            }];
            [self buttonIsPhoto];
        } else if (self.baseScrollView.contentOffset.x == WIDTH){
            [self.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.right.bottom.equalTo(self.albumButton);
                make.height.equalTo(@1);
            }];
            [self buttonIsAlbum];
        }
    }
}

#pragma mark 图片按钮夜间模式
- (void)buttonIsPhoto{
    if ([Team9EveningType shareEvening].eveningFailling) {
        [self.photoButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        [self.albumButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    } else {
        [self.photoButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        [self.albumButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
}

#pragma mark 画册按钮夜间模式
- (void)buttonIsAlbum{
    if ([Team9EveningType shareEvening].eveningFailling) {
        [self.photoButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.albumButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
    } else {
        [self.photoButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.albumButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    }
}

#pragma mark 解析热门数据
- (void)hotButton:(UIButton *)button{
    if (self.isSelect == YES) {
        [self.mainView setHidden:NO];
        [self.line setHidden:YES];
        [self.lineView setHidden:YES];
        [self.buttonView setHidden:YES];
        self.isSelect = NO;
    }else{
        [self.mainView setHidden:YES];
        [self.lineView setHidden:NO];
        [self.line setHidden:NO];
        [self.buttonView setHidden:NO];
        self.isSelect = YES;
    }if (self.styleArr.count == 0) {
    
        [Team9RefreshTool getUrl:@"http://api.meilijia.com/app/idea_photos_tags2" success:^(id result) {
            
            NSDictionary *dic = result[@"data"];
            NSDictionary *dicc = dic[@"idea_photos_tags2"];
            self.tagsArr = [NSMutableArray array];
            for (NSDictionary *DIC in dicc[@"tags"]) {
                [self.tagsArr addObject:DIC];
            }if (self.tagsArr.count != 0) {
                self.styleArr = [Team9TagsModel baseModelByArr:self.tagsArr[0][@"tags"]].mutableCopy;
            }
            [self.classifyTableView reloadData];
            
        } scrollView:self.classifyTableView empty:self.empty3];
        
    }
}

#pragma mark 解析图片数据
- (void)createData{
    NSString *str = @"http://api.meilijia.com/app/idea_photos?page=1";
    if (self.url) {
        str = [NSString stringWithFormat:@"http://api.meilijia.com/app/idea_photos?page=5&tags=%@", self.url];
    }else if (self.tagsModel) {
        str = [NSString stringWithFormat:@"http://api.meilijia.com/app/idea_photos?show_styles=1&page=1&%@",self.tagsModel.query];
        [self.hotButton setTitle:self.tagsModel.value forState:UIControlStateNormal];
    }
    self.tool = [Team9RefreshTool toolWithScrollView:self.collectionView url:str style:^NSArray *(id result) {
        return [Team9InspirationModel baseModelByArr:result[@"data"][@"idea_photos"][@"photos"]];
    } refresh:^(NSArray *array) {
        self.photoArr = array.mutableCopy;
        [self.collectionView reloadData];
        [self createAlbumData];
    } empty:self.empty];


}

#pragma mark 解析画册数据
- (void)createAlbumData{
    NSString *str = @"http://api.meilijia.com/app/idea_collections?page=1";
    if (self.url) {
        str = [NSString stringWithFormat:@"http://api.meilijia.com/app/idea_collections?page=1&tags=%@", self.url];
    }else if (self.tagsModel) {
         str = [NSString stringWithFormat:@"http://api.meilijia.com/app/idea_collections?%@&page=1",self.tagsModel.query];
    }
    self.tool2 = [Team9RefreshTool toolWithScrollView:self.albumTableView url:str style:^NSArray *(id result) {
        return [Team9AlbumModel baseModelByArr:result[@"data"][@"idea_collections"][@"collections"]];
    } refresh:^(NSArray *array) {
        self.albumArr = array.mutableCopy;
        [self.albumTableView reloadData];
    } empty:self.empty2];
}

#pragma mark collectionView返回数组个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
     return self.photoArr.count;
}

#pragma mark CollectionView赋值
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    Team9InspirationCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    
    Team9InspirationModel *model = self.photoArr[indexPath.row];
    [cell.imageView sd_setImageWithURL:[NSURL URLWithString:model.pic] placeholderImage:[UIImage imageNamed:@"111"]];
    return cell;
}

#pragma mark CollectionView点击方法
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    Team9PhotoViewController *photoVC = [[Team9PhotoViewController alloc] init];
    [self.navigationController pushViewController:photoVC animated:YES];
    Team9InspirationModel *model = self.photoArr[indexPath.row];
    photoVC.photoModel = model;
}

#pragma mark tableView返回数组个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView == self.hotTableView) {
        return self.hotArr.count;
    }else if (tableView == self.classifyTableView){
        return self.styleArr.count;
    }else if (tableView == self.albumTableView){
        return self.albumArr.count;
    }
    return 0;
}
#pragma mark tableView赋值
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == self.hotTableView) {
        static NSString *hotReuse = @"hotReuse";
        Team9BaseTableViewCell2 *cell = [tableView dequeueReusableCellWithIdentifier:hotReuse];
        if (!cell) {
            cell = [[Team9BaseTableViewCell2 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:hotReuse];
        }
        cell.textLabel.font = [UIFont systemFontOfSize:16 / WID * WIDTH];
        cell.textLabel.text = self.hotArr[indexPath.row];
        return cell;
    }else if (tableView == self.classifyTableView){
        static NSString *reuse = @"reuse";
        Team9ClassifyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (!cell) {
            cell = [[Team9ClassifyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse];
        }
        Team9TagsModel *model = self.styleArr[indexPath.row];
        cell.classifyLabel.text = model.value;
        cell.classifyLabel.highlightedTextColor = [UIColor blackColor];
        [cell.imageview sd_setImageWithURL:[NSURL URLWithString:model.pic] placeholderImage:[UIImage imageNamed:@"111"]];
        return cell;
    }else if (tableView == self.albumTableView){
        static NSString *albumReuse = @"albumReuse";
        Team9AlbumTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:albumReuse];
        if (!cell) {
            cell = [[Team9AlbumTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:albumReuse];
        }
        Team9AlbumModel *model = self.albumArr[indexPath.row];
        [cell.albumImageView sd_setImageWithURL:[NSURL URLWithString:model.cover_pic] placeholderImage:[UIImage imageNamed:@"111"]];
        [cell.upImageView sd_setImageWithURL:[NSURL URLWithString:model.items[0][@"pic"]] placeholderImage:[UIImage imageNamed:@"111"]];
        [cell.downImageView sd_setImageWithURL:[NSURL URLWithString:model.items[1][@"pic"]] placeholderImage:[UIImage imageNamed:@"111"]];
        cell.titleLabel.text = model.title;
        cell.liked_countLabel.text = model.liked_count;
        [cell.author_faceImageView sd_setImageWithURL:[NSURL URLWithString:model.author_face] placeholderImage:[UIImage imageNamed:@"333"]];
        cell.author_nickLabel.text = model.author_nick;
        cell.liked_countImageView.image = [UIImage imageNamed:@"like"];
        return cell;
    }
    return nil;
}

#pragma mark 创建热门数组
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.hotArr = [NSMutableArray arrayWithObjects:@"热门", @"风格", @"空间", @"主题", @"局部", @"装饰", @"家具", nil];
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changePage:) name:@"changePage" object:nil];
         self.albumArr = [NSMutableArray array];
        self.photoArr = [NSMutableArray array];
    }
    return self;
}

#pragma mark TableView点击方法(解析热门数据)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == self.hotTableView) {
        if (indexPath.row != 0) {
        [JQAFNetworkTool getUrl:@"http://api.meilijia.com/app/idea_photos_tags2" body:nil result:JQJSON headerFile:nil success:^(id result) {

        NSMutableDictionary *dic = result[@"data"][@"idea_photos_tags2"];
        self.styleArr = [Team9TagsModel baseModelByArr:dic[@"tags"][indexPath.row-1][@"tags"]].mutableCopy;
            [self.classifyTableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic];
        
                } failure:^(NSError *error) {
            
            }];
            self.selectRow = indexPath.row;
        }else if (indexPath.row == 0){
            if (self.baseScrollView.contentOffset.x == 0) {
                self.baseScrollView.contentOffset = CGPointMake(0, 0);
            }else{
                self.baseScrollView.contentOffset = CGPointMake(WIDTH, 0);
            }
            [self.mainView setHidden:YES];
            [self.lineView setHidden:NO];
            [self.line setHidden:NO];
            [self.buttonView setHidden:NO];
            self.isSelect = YES;
            [self.hotButton setTitle:@"热门" forState:UIControlStateNormal];
            self.tagsModel = nil;
            [self createData];
            [self.classifyTableView selectRowAtIndexPath:nil animated:NO scrollPosition:UITableViewScrollPositionNone];
            [self.hotTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:self.selectRow inSection:0] animated:NO scrollPosition:UITableViewScrollPositionNone];
        }
    }else if (tableView == self.classifyTableView){
        if (self.baseScrollView.contentOffset.x == 0) {
            self.baseScrollView.contentOffset = CGPointMake(0, 0);
            [self buttonIsPhoto];
        }else{
            self.baseScrollView.contentOffset = CGPointMake(WIDTH, 0);
        }
        self.tagsModel = self.styleArr[indexPath.row];
        [self.mainView setHidden:YES];
        [self.lineView setHidden:NO];
        [self.line setHidden:NO];
        [self.buttonView setHidden:NO];
        self.isSelect = YES;
        [self.hotButton setTitle:self.tagsModel.value forState:UIControlStateNormal];
        
        [self createData];
    }else if (tableView == self.albumTableView){
        Team9AlbumModel *model = self.albumArr[indexPath.row];
        Team9DesignVC *designVC = [Team9DesignVC new];
        designVC.url = [NSString stringWithFormat:@"http://api.meilijia.com/app/collection_page2?col_id=%ld&tab=photo", model.col_id];
        self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:designVC animated:YES];
        self.hidesBottomBarWhenPushed = NO;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
